#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define false 0
#define true  1

int ls(void)
{
  printf("entering main process\n");
  execl("/bin/ls", "ls", "-l", NULL);
  printf("exiting main process.\n");

  return 0;
}

int ls_2(void)
{
  execl("/bin/ls", "ls", "-al", "/etc/passwd", (char *)0);
  return 0;
}

static int xy_4g_network_reboot(void)
{
#if 0
  if (execl("/usr/bin/killall", "/usr/bin/killall quectel-CM", "quectel-CM", NULL) < 0) {
    printf( "killall quectel-CM fail.\n");
    return false;
  }
#endif

  system("killall quectel-CM");
  sleep(1);
  system("quectel-CM -s ctnet &");

#if 0
  if (execl("/usr/sbin/quectel-CM", "quectel-CM ", "-s ctnet \&", NULL) < 0) {
    printf("error on execl for quectel-CM\n");
    return false;
  }
#endif

  printf("4G network restart.\n");
  return true;
}

int popen_test(char * cmd)
{
  char command[64] = {0};
  FILE * fp;

  snprintf(command, sizeof(command), cmd);
  printf("cmd = %s, len = %d\n", command, strlen(cmd));

  fp = popen(command, "r");
  if (fp == NULL) {
    perror("popen fail");
    return -1;
  }

  pclose(fp);

  return 0;
}

int main()
{
  //ls();
  //ls_2();
  //xy_4g_network_reboot();
  popen_test("killall quectel-CM");

  return 0;
}


